<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    
</head>
<body>
    <script>


        // 使用var与let定义变量的区别
        var x = 6;
        console.log(x);
        {
            var x = 3;
            console.log(x);
        }
        console.log(x);//使用var定义的变量会出现问题


        var y = 6;
        console.log(y);
        {
            let y = 3;
            console.log(y);
        }
        console.log(y);
        
        
        //另外let不允许在相同作用域内，重复声明同一个变量
        console.log("--------------");
        console.log("使用let命令在同一个作用域定义一个变量");
        function func(){
            let i = 4;
            // var i = 1;
        }

        func();//报错







    </script> 
</body>

</html>